import { CCBoolean } from "cc";
import { UITransform } from "cc";
import { Sprite } from "cc";
import { CCInteger } from "cc";
import { _decorator } from "cc";
import { Component,Node } from "cc";
import NGameRes from "../../util/NGameRes";
import { color } from "cc";
import { BlockInputEvents } from "cc";
import { tween } from "cc";
const { ccclass, property } = _decorator;


/**
 * JNLayerBase
 * UI Base 类
 */
@ccclass('JNLayerBase')
export default class JNLayerBase extends Component{
    @property(CCBoolean)
    mask: boolean = false;
    @property({
        type: CCInteger,
        visible: function (this: JNLayerBase) {
            return this.mask;
        }
    })
    maskOpcity: number = 140;
    @property({
        type: CCBoolean,
        visible: function (this: JNLayerBase) {
            return this.mask;
        }
    })
    isClickMaskeClose: boolean = false;

    maskNode:Node;

    isJNClose:boolean = false;

    //加载
    onJNLoad(data?:any){
        if(this.mask){
            let node = new Node("mask");
            let ui = node.addComponent(UITransform);
            node.addComponent(BlockInputEvents);
            node.layer = this.node.layer;
            this.node.addChild(node)
            let mask = node.addComponent(Sprite);
            mask.color = color(0,0,0,this.maskOpcity);
            mask.sizeMode = Sprite.SizeMode.CUSTOM;
            NGameRes.BindSpriteFrame(mask,"ui/default_sprite_splash/spriteFrame");
            ui.width = 99999;
            ui.height = 99999;
            node.on(Node.EventType.TOUCH_START,() => {if(this.isClickMaskeClose) this.onJNClose()})
            node.setSiblingIndex(0);
            this.maskNode = node;
        }
    }

    //加载动画结束
    onJNLoadAnimEnd(){}

    //关闭
    onJNClose(){
        if(this.node.isValid)
            this.node.destroy();
    }

}
